package com.zuowei.ycy.user.ui.mine;

import android.view.View;
import android.widget.EditText;

import com.and.yzy.frame.util.RetrofitUtils;
import com.zuowei.ycy.R;
import com.zuowei.ycy.user.config.UserManger;
import com.zuowei.ycy.user.http.Member;
import com.zuowei.ycy.ui.BaseToolbarAty;

import butterknife.Bind;
import butterknife.OnClick;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

/**
 * 修改密码
 */
public class MineUpdatePwdAty extends BaseToolbarAty {
    @Bind(R.id.et_acount)
    EditText mEtAcount;
    @Bind(R.id.et_pwd)
    EditText mEtPwd;
    @Bind(R.id.et_pwd_once)
    EditText mEtPwdOnce;

    @Override
    public int getLayoutId() {
        return R.layout.mine_update_pwd_layout;
    }

    @Override
    public void initData() {
        mToolbar.setTitle("修改登录密码");
    }

    @Override
    public void requestData() {

    }

    @OnClick({R.id.tv_commit})
    @Override
    public void btnClick(View view) {
        super.btnClick(view);
        switch (view.getId()) {
            case R.id.tv_commit:
                if (mEtAcount.getText().toString().trim().length() < 6) {
                    showToast("原密码长度不对!");
                    mEtAcount.requestFocus();
                    return;
                }


                if (mEtPwd.getText().toString().trim().length() < 6) {
                    showToast("密码至少6位数");
                    mEtPwd.requestFocus();
                    return;
                }

                if (mEtPwd.getText().toString().trim().equals(mEtAcount.getText().toString().trim())) {
                    showToast("新密码和原密码不能相同");
                    mEtPwd.requestFocus();
                    return;

                }

                if (mEtPwdOnce.getText().toString().trim().length() < 6) {
                    showToast("确认密码至少6位数");
                    mEtPwdOnce.requestFocus();
                    return;
                }
                if (!mEtPwdOnce.getText().toString().trim().equals(mEtPwd.getText().toString().trim())) {
                    showToast("两次输入的密码不一致");
                    mEtPwdOnce.requestFocus();
                    return;
                }


                showLoadingDialog(null);

                doHttp(RetrofitUtils.createApi(Member.class).modifyPassword(UserManger.getM_id(), mEtAcount.getText().toString().trim(), mEtPwd.getText().toString().trim()), 1);


                break;

        }
    }


    @Override
    public void onSuccess(String result, Call<ResponseBody> call, Response<ResponseBody> response, int what) {
        showToast("修改成功");
        finish();


        super.onSuccess(result, call, response, what);
    }
}
